﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using eShop.Model;
using eShop.DataAccess;
using eShop.DataAccess.Converter;

namespace eShop.Business
{
    public class AddressManager
    {
        public static void CreateAddress(Address address)
        {
            DataAccess.Entity.Address eAddress = AddressConverter.ConvertToEntity(address);
            if (AddressDAL.Insert(eAddress))
            {
                address.Id = eAddress.Id;
            }
        }

        public static void UpdateAddress(Address address)
        {
            AddressDAL.Update(AddressConverter.ConvertToEntity(address));
        }

        public static Address GetAddressById(int id)
        {
            List<Address> addresses = AddressConverter.ConvertToModelObject(AddressDAL.GetByKeys(id, null));
            if (addresses.Count == 1)
                return (addresses[0]);
            return null;
        }

        public static List<Address> GetAddressesByUserId(int userId)
        {
            return AddressConverter.ConvertToModelObject(AddressDAL.GetByKeys(null, userId));
        }
    }
}